package com.yixing.tech.common.utils.uuid;

import java.util.Random;

/**
 * @author yixing tech
 * @description Id生成器工具类
 */
public class IdUtils {
    public static final String RANDOM_STRING = "0123456789abcdefghijklmnopqrstuvwxyz";

    /**
     * 获取随机UUID
     *
     * @return 随机UUID
     */
    public static String randomUUID() {
        return UUID.randomUUID().toString();
    }

    /**
     * 简化的UUID，去掉了横线
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String simpleUUID() {
        return UUID.randomUUID().toString(true);
    }

    /**
     * 获取随机UUID，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 随机UUID
     */
    public static String fastUUID() {
        return UUID.fastUUID().toString();
    }

    /**
     * 简化的UUID，去掉了横线，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String fastSimpleUUID() {
        return UUID.fastUUID().toString(true);
    }

    /**
     * 获取随机数
     */
    public static String getRandomCode(int num) {
        StringBuilder code = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            code.append(random.nextInt(10));
        }
        return code.toString();
    }

    public static String getRandomStringCode(int num) {
        StringBuilder code = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            code.append(RANDOM_STRING.charAt(random.nextInt(RANDOM_STRING.length() - 1)));
        }
        return code.toString();
    }
}
